# -*- coding: utf-8 -*-
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys


def click(elementobj):
    '''
    模拟js单机操作
    :param elementobj:
    :return:
    '''
    driver.execute_script("arguments[0].click()", elementobj)

def setSelect(id,item):
    '''
    模拟选择选项操作
    :param id:
    :param item:
    :return:
    '''
    list = driver.find_element_by_css_selector('div#'+id+'>div>div.form-control')
    click(list)
    opt = driver.find_elements_by_css_selector('div.gm-scroll-view>li')[item]
    flag = opt.get_attribute('class')!='dropdown-items active'
    if flag:
        click(opt)
    else:
        driver.find_element_by_css_selector('body').click()

driver = webdriver.Edge()
driver.implicitly_wait(10)  # 设置超时时间
driver.maximize_window()  # 窗口最大化显示


'''
登录网页，请改成自己的账密
'''
driver.get("https://student.gufe.edu.cn/mobile")
driver.find_elements_by_class_name('primary-btn')[2].click()
driver.find_element_by_id("oauth_uname_w").send_keys("#####")
driver.find_element_by_id("oauth_upwd_w").send_keys("####")
driver.find_element_by_class_name("oauth_check_login").click()
time.sleep(2)


'''
i签到模块，请先测试定位是否准确，确认之后，可接触确认定位的注释
'''
more = driver.find_element_by_class_name('more')
click(more)
sysapp = driver.find_elements_by_class_name('apply-tab-item')[1]
click(sysapp)
iqiandao = driver.find_elements_by_class_name('apply')[1]
click(iqiandao)
i = driver.find_elements_by_class_name('vux-tab-item.iSignList-tab')[2]
click(i)
try:
    daka = driver.find_element_by_class_name('signIn-name')

except Exception:
    print('已经打卡')
else:
    click(daka)
    time.sleep(5)
#   btn = driver.find_element_by_class_name('weui-btn').click()

'''
每日一报模块
'''


driver.get('https://student.gufe.edu.cn/app/239')
elements = driver.find_elements_by_class_name('tab')[1]
click(elements)

#填写体温
elements = driver.find_element_by_css_selector('div#number_1582879779771>input.form-control')
#清空输入框
elements.send_keys(Keys.BACK_SPACE)
elements.send_keys(Keys.BACK_SPACE)
elements.send_keys(Keys.BACK_SPACE)
elements.send_keys(Keys.BACK_SPACE)
elements.send_keys(36)

#选择选项
setSelect('select_1582372781380',3)
setSelect('select_1582372917810',3)
setSelect('select_1582372982626',2)
setSelect('select_1582373017514',1)
setSelect('select_1582372985590',1)
setSelect('select_1582373031395',1)
setSelect('select_1582373086539',1)
setSelect('select_1582373463143',2)
setSelect('select_1582373558827',1)
setSelect('checkbox_1582373560972',11)

elements = driver.find_element_by_css_selector('span.form-save')
click(elements)
time.sleep(2)

print(driver.switch_to.alert.text)
driver.switch_to.alert.accept()